package com.macaline.concurrent.demo;

public class ThreadTest extends Thread{

    public static void main(String[] args) throws InterruptedException {
        ThreadTest threadTest = new ThreadTest();
        threadTest.start();

        // 1.给threadMethod 线程加入中断点
        threadTest.interrupt();

        // 2. threadTest 线程中断状态
        System.out.println("第一次获取main的线程中断状态：" + Thread.interrupted());
        System.out.println("第二次获取main的线程中断状态：" + Thread.interrupted());
    }

    @Override
    public void run() {
        for (int i =0 ; i<10; i++){
            if(i == 5){
                // 3. 获取到当前对象的线程中断状态
//                System.out.println("第一次当前线程中断状态:" + Thread.interrupted());
//                System.out.println("第二次当前线程中断状态:" + Thread.interrupted());
                System.out.println("第一次当前线程中断状态:" + Thread.currentThread().isInterrupted());
                System.out.println("第二次当前线程中断状态:" + Thread.currentThread().isInterrupted());

                // 4.根据中断状态 结束线程
                if (Thread.interrupted()){
                    return;
                }
            }
            System.out.println("i == " + i);
        }
    }
}
